package com.lailai.service;

import com.lailai.bizobject.BizObject;
import com.lailai.domainservice.response.Response;
import com.lailai.service.impl.AppConfiguration;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.function.Function;

/**
 * @Author lgr
 * @Date 2025/9/18
 * @Description 抽象的领域服务类，提供默认实现，子类可重写
 * @Email 983105834@qq.com
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public abstract class AbstractDomainService implements DomainService, IBoxedService {
    private final Logger logger = LoggerFactory.getLogger(AbstractDomainService.class);
    protected String schemaCode;
    @Autowired
    protected AppConfiguration appConfiguration;
    @Autowired
    protected AppService appService;
    @Autowired
    protected CrossDomainServiceCaller crossDomainServiceCaller;

    @Override
    public Response create(List<BizObject> bizObjects) {
        // 默认实现，可根据需要重写
        Response response = new Response();
        response.setSuccess(true);
        return response;
    }

    public final void initBoxedService(HashMap<String, Object> context, Function<Object, Object> interAppCallback) {
//        Class<?>[] argTypes = new Class[]{AppConfiguration.class, Function.class};
//        Object[] args = new Object[]{this.appConfiguration, interAppCallback};
//        this.invokeContext = context;
//        this.crossDomainServiceCaller = (CrossDomainServiceCaller)EnhancedServiceLoader.load(CrossDomainServiceCaller.class, argTypes, args);
//        argTypes = new Class[]{AppConfiguration.class, CrossDomainServiceCaller.class};
//        args = new Object[]{this.appConfiguration, this.crossDomainServiceCaller};
//        this.appService = (AppService)EnhancedServiceLoader.load(AppService.class, argTypes, args);
    }
}
